<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '楼盘项目管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="jjr-project-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php Pjax::begin(); ?>

    <p>
        <?= Html::a('创建楼盘项目', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'name',
            'price',
            //'main_pic',
            'commission_ad',
             ['attribute'=>'status','value'=>function($model){
                    if($model->status==1){
                        return '已审核';
                    }else if($model->status==0){
                        return '未审核';
                    }

             }],
                'create_time',
            //'commission_percent',
            //'commission_fix',
            //'commission_type',
            //'adviser',
            //'adviser_mobile',
            //'description',
            //'address',
            //'longitude',
            //'latitude',
            //'create_time',
            //'update_time',


            ['class' => 'yii\grid\ActionColumn','template' => '{audit}{house}{view}{update}{delete}','buttons' => [

                'audit' => function ($url,$model, $key) {
                    if($model->status==1){
                        return Html::a('<span class="glyphicon glyphicon-remove-sign"></span>', $url, ['title'=> '取消审核'] );
                    }else if($model->status==0){
                        return Html::a('<span class="glyphicon glyphicon-ok-sign"></span>', $url, ['title'=> '审核'] );

                    }



                },
                'house'=>function($url,$model, $key){ //glyphicon glyphicon-home
                    return Html::a('<span class="glyphicon glyphicon-home"></span>', $url, ['title'=> '户型管理'] );
                }

            ],
                'urlCreator' => function ($action, $model, $key, $index) {
                    switch($action)
                    {
                        case 'audit':
                            if($model->status==0){
                                return \yii\helpers\Url::toRoute('/jjr-project/audit?id='.$model->id);
                            }else{
                                return \yii\helpers\Url::toRoute('/jjr-project/cancel-audit?id='.$model->id);
                            }

                            break;
                        case 'house':
                            return \yii\helpers\Url::toRoute('/jjr-project-house/index?id='.$model->id);
                            break;
                        case 'update':
                            return \yii\helpers\Url::toRoute('/jjr-project/update?id='.$model->id);
                            break;
                        case 'delete':
                            return \yii\helpers\Url::toRoute('/jjr-project/delete?id='.$model->id);
                            break;
                        case 'view':
                            return \yii\helpers\Url::toRoute('/jjr-project/view?id='.$model->id);
                            break;

                    }

                },

                'header' => '操作',

            ],
        ],
    ]); ?>
    <?php Pjax::end(); ?>
</div>

<!-- 定义数据块 -->
<?php $this->beginBlock('test'); ?>
jQuery(document).ready(function() {
highlight_subnav('jjr-project/index'); //子导航高亮
});
<?php $this->endBlock() ?>
<!-- 将数据块 注入到视图中的某个位置 -->
<?php $this->registerJs($this->blocks['test'], \yii\web\View::POS_END); ?>
